package com.zhdl.hardware.robot.fair.repository.impl;

import com.project.command.faq.event.behavior.BehaviorPerform;
import com.zhdl.hardware.robot.fair.repository.FairPortCmdHandleDao;
import com.zhdl.modules.tools.CommonCallback;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
@Service
public class FairPortCmdHandleDaoImpl implements FairPortCmdHandleDao {

    @Resource
    public BehaviorPerform behaviorPerform;

    public Map<String, FairCmdHandleDaoImpl> daoMap = new ConcurrentHashMap<>();



    /**
     * 初始化网口
     *
     * @param port 网口地址
     */
    public void addPort(String port) {
        FairCmdHandleDaoImpl fairCmdHandleDao = new FairCmdHandleDaoImpl(port, behaviorPerform);
        daoMap.put(port, fairCmdHandleDao);
    }

    /**
     * 法奥机器人-控制机器人动作指令
     *
     * @param port  网口
     * @param cmd   指令
     */
    @Override
    public void FairRobotAction(String port, String cmd, CommonCallback<String> callback){
        daoMap.get(port).FairRobotAction(cmd, callback);
        log.info("指令发送地址->"+ port +",指令为->" + cmd);
    }

    /**
     * 法奥机器人-读取机器人当前关节坐标
     *
     * @param cmd 指令
     */
    @Override
    public void FairRobotGetJointPos(String port, String cmd, CommonCallback<String> callback){
        daoMap.get(port).FairRobotAction(cmd, callback);
        log.info("指令发送地址->"+ port +",指令为->" + cmd);
    }

}
